#!/usr/bin/perl
# edit_serv.cgi
# edit or create a device

require './mdmsearch-lib.pl';
&ReadParse();

&header($text{'edit_title'}, "", "edit", 0, 1);

$s = &get_server($in{'id'});
local $control=$s->{'user'}?1:0;
print "<form name=editserv action=save_serv.cgi method=post>\n";
print "<input type=hidden name=id value='$in{'id'}'>\n";
print "<input type=hidden name=deal value='save'>\n";

print "<table class=mode1 border=0 cellpadding=5 cellspacing=0>\n";
print "<tr><table class=mode1 border=0 cellpadding=5 cellspacing=0>\n";
 print "<tr><td><b>$text{'systemid'}:</b></td><td>$s->{'id'}</td></tr>\n";
 print "<tr><td><b>$text{'hostname'}:</b></td><td><input name=hostname value=$s->{'hostname'}></td></tr>\n";
 print "<tr><td><b>$text{'ip'}:</b></td><td><input name=ip value=$s->{'ip'}></td></tr>\n";
print "</table></tr>\n";
print "<tr><table class=mode1 border=0 cellpadding=5 cellspacing=0>\n";
 printf "<tr><td><input type=checkbox %s name=controlled value='yes' onclick ='return enable_control();'>\n",$control?'checked':'';
 print "<b>$text{'controll_dev'}</b></td></tr>\n";
 printf "<tr><td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<b>$text{'user'}:&nbsp&nbsp</b><input %s name=user value=$s->{'user'}></td></tr>\n",$control?'':'disabled';
 printf "<tr><td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<b>$text{'passwd'}:&nbsp&nbsp</b><input type=password %s name=passwd value=$s->{'passwd'}></td></tr>\n",$control?'':'disabled';
#print "</table></tr>\n";
print "<tr><table class=mode1 border=0 cellpadding=5 cellspacing=0>\n";
 print "<tr><td><input type=submit class=button1 name=savedev value='$text{'submin'}'></td>\n";
 print "<td><input type=submit class=button1 name=deldev value='$text{'delete'}' onclick='return want_delete(\"$text{'meg_confirmdel'}\");'></td></tr>\n";
print "</table></tr>\n";
print "</table>\n";
print "</form>\n";

print <<EOF;
<script>
function enable_control()
{
	if (document.editserv.controlled.checked){
		document.editserv.user.disabled = false;
		document.editserv.passwd.disabled = false;
	}else{
		document.editserv.user.disabled = true;
		document.editserv.passwd.disabled = true;
	}
}

function want_delete(confirm_msg)
{
        if(!confirm(confirm_msg))
        {
                return false;
        }	
        
        document.editserv.deal.value="del";
}

</script>
EOF


&footer("index.cgi",$text{'index_title'});
1;